package speech;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class Speaker {
	private Voice voice;

	public Speaker() {
		VoiceManager voiceManager = VoiceManager.getInstance();

		voice = loadVoice(voiceManager);

		voice.allocate();
	}

	public void speak(String message) {
		voice.speak(message);
	}

	public void cleanUp() {
		voice.deallocate();
	}

	private Voice loadVoice(VoiceManager voiceManager) {
		String voiceName = "kevin16";
		Voice voice = voiceManager.getVoice(voiceName);

		if (voice == null) {
			System.err.println("Cannot find a voice named " + voiceName + ".  Please specify a different voice.");
			System.exit(1);
		}
		return voice;
	}
}
